//
//  EFFeatureHeadView.m
//  EnjogFood
//
//  Created by 王芳 on 17/5/6.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFFeatureHeadView.h"
#import "EFFearchItem.h"
#import "EFEventPromotionViewController.h"

@interface EFFeatureHeadView ()
@property (strong, nonatomic) UILabel *titleLable;
@property (strong, nonatomic) UILabel *descriprtionLabel;
@property (strong, nonatomic) UIView *line;
@property (strong, nonatomic) UIImageView *backgroundImageV;

@property (strong, nonatomic) EFFearchItem *item;
@end

@implementation EFFeatureHeadView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    [self addSubview:self.backgroundImageV];
    [self addSubview:self.titleLable];
    [self addSubview:self.line];
    [self addSubview:self.descriprtionLabel];
}

-(void)refreshUI:(EFFearchItem *)featureItem{
    self.item = featureItem;
    [self.backgroundImageV setImageWithURL:[NSURL URLWithString:featureItem.img]];
    
    self.titleLable.text = featureItem.title;
    [self.titleLable sizeToFit];
    self.titleLable.left = 20;
    self.titleLable.top = 19;
    self.titleLable.width = 145;
    
    self.line.left = self.titleLable.left;
    self.line.top = self.titleLable.bottom + 4;
    
    self.descriprtionLabel.text = [NSString stringWithFormat:@"%@\rn%@",featureItem.desc1,featureItem.desc2];
    [self.descriprtionLabel sizeToFit];
    self.descriprtionLabel.left = self.titleLable.left;
    self.descriprtionLabel.top = self.line.bottom + 10;
}

- (UILabel *)titleLable{
    if (!_titleLable) {
        _titleLable = [[UILabel alloc] init];
        _titleLable.font = [UIFont systemFontOfSize:19];
        _titleLable.textColor = kBlack333;
    }
    return _titleLable;
}

- (UILabel *)descriprtionLabel{
    if (!_descriprtionLabel) {
        _descriprtionLabel = [[UILabel alloc] init];
        _descriprtionLabel.font = [UIFont systemFontOfSize:10];
        _descriprtionLabel.textColor = kBlack666;
        _descriprtionLabel.numberOfLines = 0;
    }
    return _descriprtionLabel;
}

- (UIView *)line{
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 2)];
        _line.backgroundColor = kBlack333;
    }
    return _line;
}

- (UIImageView *)backgroundImageV{
    if (!_backgroundImageV) {
        _backgroundImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 165, 240)];
        _backgroundImageV.backgroundColor = RGBCOLOR(0xf3f3f3);
        _backgroundImageV.userInteractionEnabled = YES;
        [_backgroundImageV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(turnToPage)]];
        _backgroundImageV.contentMode = UIViewContentModeScaleAspectFill;
        _backgroundImageV.clipsToBounds = YES;
    }
    return _backgroundImageV;
}

- (void)turnToPage{
    EFEventPromotionViewController *vc = [[EFEventPromotionViewController alloc] initWithEventId:[NSNumber numberWithInteger:self.item.catgoryId.integerValue]];
    [ICNavigator pushViewController:vc animated:YES];
}

@end
